package com.neusoft.config;

import com.github.pagehelper.PageInterceptor;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class MybatisConfig {




    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        ssfb.setTypeAliasesPackage("com.neusoft.domain");
        ssfb.setDataSource(dataSource);
        // 配置分页插件----------------------
        Properties properties = new Properties();
        // 这里可以设置PageHelper相关参数，例如reasonable、supportMethodsArguments等
        properties.setProperty("reasonable", "true");
        properties.setProperty("helper-dialect", "mysql");
        PageInterceptor pageInterceptor = new PageInterceptor();
        pageInterceptor.setProperties(properties);
        ssfb.setPlugins(pageInterceptor);
        return ssfb;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.neusoft.mapper");
        return msc;
    }

}
